<h1><?php echo ucwords($pageName); ?></h1>
<hr />
<?php
	if (isset($_GET['type']) && (empty($_POST['id']) || !isset($_POST['modifCharac']))){
	//Profil == 1
?>			
			<div class="change_type">
				<a href="caracteristiques.php" class="lienCarac" >Changer le type de caract&eacute;ristique</a>
			</div><br /><br />
			<h2>Ajouter une caract&eacute;ristique</h2><br />
			<div class="addCarac">
				<form method="post" action="<?php echo $requestURI, "?type=", $_GET['type']; ?>">
					<table>
					<tr><td>
					Nom : </td><td>
					<input type="text" name="name" class="inputText"/></td></tr>
					<tr><td>Type de caract&eacute;ristiques : </td><td>
					<select id="nom" name="kindOfSelect" onchange="if ($('#nom option:selected').val() == '1' ) $('#all_tr *').fadeOut(400); else $('#all_tr *').fadeIn(400);">
						<option value="2" >Case &agrave; cocher</option>
						<option value="1" >Bouton radio</option>
					</select></td></tr>
					<tr id="all_tr"><td>Sans importance</td>
					<td><input id="all" type="checkbox" name="any" value="1" style="display:block" /></td>
					</table><br />
					<input type="submit" name="addCharac" class="submit" value="Ajouter">
				</form>
			</div>
			<hr /><br />
			<h2>Modifier une caract&eacute;ristique</h2><br />
			<form method="post" action="<?php echo $requestURI, "?type=", $_GET['type']; ?>">
			<select name="id">
<?php
			$c = count($carac) ;
			for ($i = 0; $i < $c; $i++){
				echo '<option value="', $carac[$i]->idCharacteristic , '" >', $carac[$i]->name, '</option>';
			}
?>
			</select><br /><br />
			<input type="submit" class="submit" name="modifCharac" value="S&eacute;lectionner" />
			</form>
			<hr /><br />
			<h2>Supprimer une caract&eacute;ristique</h2><br />
			<form method="post" action="<?php echo $requestURI, "?type=", $_GET['type']; ?>">
			<select name="id">
<?php
			$c = count($carac) ;
			for ($i = 0; $i < $c; $i++){
				echo '<option value="', $carac[$i]->idCharacteristic , '" >', $carac[$i]->name, '</option>';
			}
?>
			</select><br /><br />
			<input type="submit" class="submit" name="delCharac" value="Supprimer" />
			</form><br />
<?php
	}elseif (!empty($_POST['id'])){
?>
	<div class="change_type">
		<a href="caracteristiques.php?type=<?php echo $_GET['type'];?>" class="lienCarac" >Changer de caract&eacute;ristique</a>
	</div>
	<div class="addCarac">
		<form method="post" action="<?php echo $requestURI, "?type=", $_GET['type']; ?>">
		<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>" />
			<table>
			<tr><td>
			Nom : </td><td>
			<input type="text" name="name" class="inputText" value="<?php echo $charac->name; ?>"/></td></tr>
			<tr><td>Type de caract&eacute;ristiques : </td><td>
			<select id="nom" name="kindOfSelect" onchange="if ($('#nom option:selected').val() == '1' ) $('#all_tr *').fadeOut(400); else $('#all_tr *').fadeIn(400);">
				<option value="2" <?php echo ($charac->kindOfSelect == 2)?'selected="selected"':''; ?>>Case &agrave; cocher</option>
				<option value="1" <?php echo ($charac->kindOfSelect == 1)?'selected="selected"':''; ?> >Bouton radio</option>
			</select></td></tr>
			<tr id="all_tr"><td>Sans importance</td>
			<td><input id="all" type="checkbox" name="any" value="1" <?php echo ($charac->all)?'checked="checked"':''; ?> style="display:block" /></td>
			</table><br />
			<input type="submit" class="submit" name="updateCharac" value="Modifier" />
		</form><br />
	</div>
	<h2>Valeur(s) associ&eacute;e(s)</h2><br />
	<form method="post" action="<?php echo $requestURI, "?type=", $_GET['type'];  ?>" >
	<input type="hidden" name="type" value="<?php echo $_GET['type']; ?>" />
	<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>" />
	<?php 	
		$val = $charac->_values;
		$c = count($val);
		for ($i = 0; $i < $c; $i++){
			echo '<input type="text" class="inputText" name="' . $val[$i]['id'] . '" value="' . $val[$i]['value'] . '" /> <a href="caracteristiques.php?type='. $_GET['type'] .'&deleteValue=1&id=' . $val[$i]['id'] . '"><img src="' . IMG_DIR . 'cross.png" alt="Supprimer" /></a>', "<br />\n";
		}
	?>
	<div id="newElement">
	</div>
	<input type="hidden" name="count" id="count" value="0" />
	<img class="addVal" id="addVal" src="<?php echo IMG_DIR; ?>ajouter.png" alt="Ajouter" /><br /><br />
	<script type="text/javascript">
		$('#addVal').click(function(){
			val = $('#count').attr('value');
			elem = $('<input type="text" class="inputText" id="new' + val + '" name="new' + val + '" value="" /> <img src="<?php echo IMG_DIR; ?>cross.png" alt="Supprimer" style="visibility:hidden" /><br />');
			$('#newElement').append(elem).fadeOut(0).fadeIn(400);
			$('#count').attr('value', (parseInt($('#count').attr('value')) + 1) );
			$('#exists').fadeIn(400);
		});
	</script>
	<div id="exists">
	Valeurs existantes : 
	<select name="exists" id="valExist">
		<?php 
			$c = count ($values);
			for ($i = 0; $i < $c; $i++){
				echo '<option value="' . $values[$i]['idValue'] . '">' . $values[$i]['value'] . '</option>';
			}
		?>
	</select><br /><br />
	</div>
	<script type="text/javascript">
	val = $('#count').attr('value');
	$('#exists').fadeOut();
				$('#valExist').click(function(){  $('#new'+val).attr('value',$('#valExist option:selected').html()); });
	</script>
	<input type="submit" class="submit" name="updateValues" value="Modifier" /><br /><br />
	</form>
<?php
	}else{
?>
	<br />
	<table class="caracType"><tr><td>
	<div class="submit">
	<a href="caracteristiques.php?type=1" class="lienCarac" >Caract&eacute;ristiques de profils</a>
	</div></td><td>&nbsp;&nbsp;&nbsp;</td><td>
	<div class="submit">
	<a href="caracteristiques.php?type=2" class="lienCarac" >Caract&eacute;ristiques de logements</a>
	</div></td></tr></table>
<?php
	}
?>